/* -------------------------------------------------------------------------
 *
 * rowsecurity.h
 *
 *	  用于 rewrite/rowsecurity.c 的原型和管理关系的行安全策略的结构
 *	  在 relcache 中。
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * -------------------------------------------------------------------------
 */
#ifndef ROWSECURITY_H
#define ROWSECURITY_H

#include "nodes/parsenodes.h"
#include "utils/array.h"
#include "utils/relcache.h"

typedef struct RowSecurityPolicy
{
	char	   *policy_name;	/* 策略名称 */
	char		polcmd;			/* 命令策略的类型 */
	ArrayType  *roles;			/* 策略适用的角色数组 */
	bool		permissive;		/* 限制性或宽松策略 */
	Expr	   *qual;			/* 过滤行的表达式 */
	Expr	   *with_check_qual;	/* 限制允许行数的表达式 */
	bool		hassublinks;	/* 如果任一表达式有子链接 */
} RowSecurityPolicy;

typedef struct RowSecurityDesc
{
	MemoryContext rscxt;		/* 行安全内存上下文 */
	List	   *policies;		/* 行安全策略列表 */
} RowSecurityDesc;

typedef List *(*row_security_policy_hook_type) (CmdType cmdtype,
												Relation relation);

extern PGDLLIMPORT row_security_policy_hook_type row_security_policy_hook_permissive;

extern PGDLLIMPORT row_security_policy_hook_type row_security_policy_hook_restrictive;

extern void get_row_security_policies(Query *root,
									  RangeTblEntry *rte, int rt_index,
									  List **securityQuals, List **withCheckOptions,
									  bool *hasRowSecurity, bool *hasSubLinks);

#ifdef FDD
typedef List *(*fdb_mac_restrictive_hook_type) (CmdType cmdtype, Relation relation, RangeTblEntry *current_handle_rte, List *poliyColumns);
typedef List *(*fdb_mac_permissive_hook_type) (Relation relation);
typedef bool (*fdb_rel_need_mac_check_hook_type)(Oid relid, List **poliyColumns);

extern bool fdb_need_mac(Oid relid, List **poliyColumns);
#endif

#endif							/* ROWSECURITY_H */
